package com.demo.transaction.services.hello.impl;

import com.demo.transaction.repository.primary.hello.domain.PrimaryHello;
import com.demo.transaction.repository.secondary.hello.mapper.SecondaryHelloMapper;
import com.demo.transaction.services.hello.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class HelloServiceImpl implements HelloService {

//    @Autowired
//    PrimaryHelloMapper primaryHelloMapper;


    @Autowired
    SecondaryHelloMapper secondaryHelloMapper;



    @Override
    public void add() {
        String value = "v";
//        this.addPrimary(value);
        this.addSecondary(value);
    }

    //    @Transactional(transactionManager = "primaryDataSourceTransactionManager", propagation = Propagation.REQUIRED)
    public void addPrimary(String value) {
//        this.primaryHelloMapper.insert(value);
    }

    @Transactional(transactionManager = "secondaryDataSourceTransactionManager")
    public void addSecondary(String value) {
        this.secondaryHelloMapper.insert(value);
        throw new RuntimeException("测试事物");
    }

    @Override
    public PrimaryHello get(Integer id) {
        return null;
    }

    @Override
    public List<PrimaryHello> list() {
        return null;
    }
}
